home *** CD-ROM | disk | FTP | other *** search
/ LiquidLibrary 2005 September / LiquidLibrary 2005 Sep - Disc 1.iso / pc / Portfolio Browser / Filters / PDF / LIB / gs_fform.ps < prev    next >
Text File  |  2003-01-03  |  3KB  |  83 lines

  1. %    Copyright (C) 1995, 1996, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2. % This software is licensed to a single customer by Artifex Software Inc.
  3. % under the terms of a specific OEM agreement.
  4.  
  5. % $RCSfile$ $Revision$
  6. % Form caching implemented in PostScript.
  7.  
  8. % This implementation doesn't do the right thing about halftone or
  9. % Pattern phase, but the Pattern cache doesn't either....
  10.  
  11. % The Form cache key is the Form dictionary; the value is an array
  12. % of 2 elements [CTM pattern_instance].
  13. %
  14. % In order to prevent restore from clearing the cache, we explicitly
  15. % push the cache entries on the stack before a restore and reinstall them.
  16. currentglobal false setglobal
  17. /.formcachedict 20 dict def    % must be local
  18. true setglobal
  19. /restore {
  20.   mark .formcachedict { } forall
  21.   counttomark 1 add index { //restore } .internalstopped
  22.     { cleartomark //restore }
  23.     { counttomark 2 idiv { .formcachedict 3 1 roll put } repeat pop pop }
  24.   ifelse
  25. } bind odef
  26.  
  27. /.execform1 {
  28.   dup /Implementation known not {
  29.     dup /FormType get 1 ne { /rangecheck signalerror } if
  30.         % The Implementation is a Pattern that will draw the form.
  31.     currentglobal 1 index gcheck setglobal
  32.         % Stack: form global
  33.     10 dict begin
  34.       /PatternType 1 def
  35.       /PaintType 1 def    % colored
  36.       /TilingType 1 def    % irrelevant
  37.         % Copy the BBox to the correct VM.
  38.       /BBox 2 index /BBox get 4 array copy exch 1 index def
  39.         % Set XStep and YStep to very large numbers,
  40.         % so we won't get multiple copies of the form.
  41.       /XStep 1 index dup 2 get exch 0 get sub 100 mul def
  42.       /YStep exch dup 3 get exch 1 get sub 100 mul def
  43.       /PaintProc 2 index /PaintProc get def
  44.     currentdict end readonly
  45.         % Stack: form global impl
  46.     exch setglobal
  47.     1 index /Implementation 3 -1 roll .forceput
  48.   } if
  49.   .formcachedict 1 index .knownget {
  50.         % Check whether we can use the cached value.
  51.         % Stack: form cachevalue
  52.     matrix currentmatrix true 0 1 3 {
  53.         % Stack: form cachevalue curmat true index
  54.       3 index 0 get 1 index get exch 3 index exch get ne {
  55.     pop pop false exit
  56.       } if
  57.     } for exch pop
  58.   } {
  59.     false
  60.   } ifelse not
  61.   {        % Make a new cache entry.
  62.     gsave
  63.     matrix currentmatrix dup 4 0 put dup 5 0 put dup setmatrix
  64.         % Stack: form mat
  65.     1 index /Implementation get
  66.     2 index /Matrix get
  67.     makepattern 2 array astore
  68.     .formcachedict 2 index 2 index put
  69.     grestore
  70.   } if
  71.         % Stack: form cachevalue
  72.   -1 0 0 transform
  73.   2 { exch round cvi } repeat .setscreenphase
  74.   1 get setpattern
  75.   /BBox get aload pop
  76.   exch 3 index sub exch 2 index sub rectfill
  77. } .bind odef    % must bind .forceput
  78.  
  79. .formtypes 1 /.execform1 load put
  80.  
  81. setglobal
  82.